#ifndef _TIMER_H_
#define _TIMER_H_

/** @defgroup TIMER TIMER
 * @{
 *
 * Aqui estão as funções que manipulam os timers 2 e 0, necessários para o speaker e contador, respectivamente 
 */

#define TIMER_0      0x40 /* Endereço do timer0                 */
#define TIMER_1      0x41 /* Endereço do timer1                 */
#define TIMER_2      0x42 /* Endereço do timer2                 */
#define TIMER_CTRL   0x43 /* Endereço do controlador dos timers */

#define SPEAKER_CTRL    0x61    ///< Port number of PC register whose bits 0 and 1 control TIMER_2  and the output to the speaker
#define TIMER2_ENABLE  (1 << 0) ///< Enable Timer2, bit 0 to 1
#define SPEAKER_ENABLE (1 << 1) ///< Enable output to speaker, bit 1 to 1

#define TIMER_CLK    1193181 	///< Frequência de entrada dos timers

#define LSBMSB       0x30       ///< LSB followed by MSB
#define MODE2	       0x04       ///< Counting mode 2: freq. div (impulse)
#define MODE3        0x06       ///< Counting mode 3: freq. div (square wave)
#define BCD          0x01       ///< BCD counter

/**
 * Põe o timer 0, 1 ou 2 no modo especificado
 */
void timer_init(int timer, int mode);

/**
 * Põe o valor especificado no timer 0, 1 ou 2
 */
void timer_load(int timer, int value);

/** Variável usada pelo timer0 para medir o tempo  */

extern int millis;

/** ISR do timer0 */

void t0_isr();  

/** Configura o timer0
 */
void setup_timer0();

/** Restaura a configuração inicial do timer0
 */
void restore_timer0();

/** Faz uma pausa de ms milissegundos
*/
void msleep(int ms);

/** @} End of TIMER */

#endif
